package com.bigdata.spark.testapp.JsonTest;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bigdata.spark.java.entity.Doctor;
import com.bigdata.spark.java.utils.jdbcutil.DateUtils;
import org.json.JSONArray;

import java.text.SimpleDateFormat;
import java.util.Date;

public class JsonTestjava {
    public static void main(String[] args) {



     //==========================================bean 转string

        Student student = new Student("lily", 12);
        String jsonString = JSONObject.toJSONString(student);
        System.out.println(jsonString);



        user user = new user("aaaa", "bane", "nan", "1234", "1212344");
        Object a1 = JSONObject.toJSON(user);
        System.out.println("a1"+a1.toString());

        //=========================================

        String qst1 = "{\"actions\":[{\"action_id\":\"trade_add_address\",\"ts\":1592204452917}],\"common\":{\"ar\":\"370000\",\"ba\":\"Xiaomi\",\"ch\":\"oppo\",\"md\":\"Xiaomi Mix2 \",\"mid\":\"mid_24\",\"os\":\"Android 11.0\",\"uid\":\"190\",\"vc\":\"v2.1.132\"},\"page\":{\"during_time\":4462,\"item\":\"2,4,5\",\"item_type\":\"sku_ids\",\"last_page_id\":\"orders_unpaid\",\"page_id\":\"trade\"},\"ts\":1592204450686}\n";


        System.out.println(qst1);


        JSONObject jsonObject0 = JSON.parseObject(qst1);

        JSONObject startJson0 = jsonObject0.getJSONObject("page");
        Object during_time = startJson0.get("during_time");
        System.out.println("during_time"+during_time);



        JSONObject during_time1 = jsonObject0.getJSONObject("common");
        System.out.println("common"+during_time1.values().toString());



        //System.out.println("qqqqqqqqqqqqqq"+startJson0.values().toString());


        String st = "{\"start\":{\"userid\":\"1\",\"username\":\"1\",\"sex\":\"北京\",\"phone\":\"112344321\",\"ts\":1630915041064}}";

        System.out.println(st);

        JSONObject jsonObject = JSON.parseObject(st);
        JSONObject startJson = jsonObject.getJSONObject("start");

        Object userid = startJson.get("userid").toString();


        System.out.println(userid);

    }
}
